package com.hyh.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class TUtil {
    public static <T> T getT(Object o, int i) {
        try {
            Type type = o.getClass().getGenericSuperclass();
            if(type instanceof ParameterizedType){
                return ((Class<T>) ((ParameterizedType) (type)).getActualTypeArguments()[i])
                        .newInstance();
            }else if(type instanceof Class){
                ParameterizedType typ = (ParameterizedType) ((Class)type).getGenericSuperclass();
                return ((Class<T>)typ.getActualTypeArguments()[i]).newInstance();
            }
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        } catch (ClassCastException e) {
        }
        return null;
    }
}
